package com.freewater.javabase.demo.mutithread.interrupt;

public class Interrupt3 {

    public static void main(String[] args) throws InterruptedException {
        HelloThread helloThread = new HelloThread();
        helloThread.start();
        Thread.sleep(20);
        helloThread.running = false;
        helloThread.join();
    }

    public static class HelloThread extends Thread {
        private volatile boolean running = true;// volatile解决线程之间变量的可见性

        @Override
        public void run() {
            int n = 0;
            while (running) {
                System.out.println(n++ + " hello");
            }
        }
    }
}
